package com.cn.lycss.servlet.user;

import com.alibaba.fastjson.JSONObject;
import com.cn.lycss.model.ResultModel;
import com.cn.lycss.model.UserModel;
import com.cn.lycss.service.UserService;
import com.cn.lycss.service.impl.UserServiceImpl;
import com.cn.lycss.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/user/findAll")
public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setCharacterEncoding("utf-8");
req.setCharacterEncoding("utf-8");


        String username = req.getParameter("username");
        String email = req.getParameter("email");
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String phone = req.getParameter("phone");
        String sex = req.getParameter("sex");
        String hobby = req.getParameter("hobby");
        String enable =req.getParameter("enable");
        String pageNo=req.getParameter("pageNo");
        String pageSize=req.getParameter("pageSize");
        //        2.将数据封装到model
        UserModel userModel = new UserModel();
        userModel.setPageSize(Tool.aa(pageSize));
        userModel.setPageNumber(Tool.aa(pageNo));

        userModel.setUsername(username);

        userModel.setSex(sex);
        userModel.setStart(start);
        userModel.setEnd(end);

        userModel.setEnable(Tool.aa(enable));
        userModel.setHobby(hobby);
        userModel.setPhone(phone);


        UserService userService=new UserServiceImpl();
      ResultModel resultModel= userService.findAll(userModel);
      resp.getWriter().print(JSONObject.toJSONString(resultModel));

    }
}
